home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / ANIVGA.ARJ / EXAMPLE2.PAS < prev    next >
Pascal/Delphi Source File  |  1991-11-09  |  2KB  |  81 lines

  1. PROGRAM Example2;
  2.  
  3. {Demonstrates using scrolling backgrounds}
  4.  
  5. USES ANIVGA,CRT;
  6. CONST Tile_Name='tile2.COD';    {4 simple tiles}
  7.       Sprite_Name='flower.COD';
  8.  
  9. VAR ch:Char;
  10.     i,j:Integer;
  11.     temp:WORD;
  12.     collide:BOOLEAN;
  13.  
  14. PROCEDURE Init;
  15. VAR gx,gy,count:INTEGER;
  16. BEGIN
  17.  XTiles:=0; YTiles:=0;
  18.  SetBackgroundMode(scrolling);
  19.  SetBackgroundScrollRange(-500,-500,100,100);
  20.  
  21.  {paste tiles into this background, using circular enumeration 0,1,2,3,0,...}
  22.  count:=0;
  23.  gy:=BackY1;
  24.  REPEAT
  25.   gx:=BackX1;
  26.   REPEAT
  27.    PutTile(gx,gy,count);
  28.    inc(count); count:=count mod 4;
  29.    inc(gx,16);
  30.   UNTIL gx>BackX2;
  31.   inc(gy,16);
  32.  UNTIL gy>BackY2;
  33.  
  34.  {Set SPRITEAD[10]:}
  35.  IF loadSprite(Sprite_Name,10)=0
  36.   THEN BEGIN
  37.         WRITELN(GetErrorMessage); halt(1)
  38.        END;
  39. END;
  40.  
  41. BEGIN
  42.  Init;
  43.  InitGraph;
  44.  temp:=LoadTile(Tile_Name,0); {load the 4 tiles & give them the numbers 0..3}
  45.  IF Error<>Err_None
  46.   THEN BEGIN
  47.         CloseRoutines;
  48.         WRITELN(GetErrorMessage); halt(1)
  49.        END;
  50.  
  51.  SetCycleTime(0); {animation as fast as possible}
  52.  
  53.  SpriteN[0]:=10; SpriteX[0]:=0;   SpriteY[0]:=0;
  54.  SpriteN[5]:=10; SpriteX[5]:=100; SpriteY[5]:=100;
  55.  
  56.  WHILE keypressed DO ch:=readkey;
  57.  Animate;
  58.  REPEAT
  59.   collide:=Hitdetect(0,5);
  60.   IF collide THEN BEGIN sound(1000); delay(5); nosound END;
  61.   if KeyPressed
  62.    THEN BEGIN
  63.          WHILE KeyPressed DO ch:=Upcase(ReadKey);
  64.          CASE ch OF
  65.           'I':dec(SpriteY[0]);  {change position of sprite with I,J,K,M}
  66.           'J':dec(SpriteX[0]);
  67.           'K':inc(SpriteX[0]);
  68.           'M':inc(SpriteY[0]);
  69.           'E':dec(StartVirtualY,10);  {change position of whole scene with}
  70.           'S':dec(StartVirtualX,10);  {E,S,D,X}
  71.           'D':inc(StartVirtualX,10);
  72.           'X':inc(StartVirtualY,10);
  73.          END;
  74.          IF POS(ch,'IJKMESDX')>0 THEN Animate;
  75.         END;
  76.  
  77.  UNTIL ch='Q';  {"Q" to quit}
  78.  
  79.  CloseRoutines;
  80.  
  81. END.